﻿<RibbonWindow x:Class="Waf.Writer.Presentation.Views.ShellWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:c="clr-namespace:Waf.Writer.Presentation.Converters"
    xmlns:p="clr-namespace:Waf.Writer.Presentation.Properties"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:dd="clr-namespace:Waf.Writer.Presentation.DesignData"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="clr-namespace:Waf.Writer.Applications.ViewModels;assembly=Waf.Writer.Applications"
    mc:Ignorable="d" d:DataContext="{d:DesignInstance dd:SampleShellViewModel, IsDesignTimeCreatable=True}"
    x:Name="shellWindow" Icon="{StaticResource WriterImageSource}"
    Height="600" Width="900">
    
    <Window.Title>
        <MultiBinding Converter="{StaticResource TitleConverter}">
            <Binding Path="Title"/>
            <Binding Path="ShellService.DocumentName"/>
        </MultiBinding>
    </Window.Title>

    <Window.InputBindings>
        <KeyBinding Command="{Binding FileService.NewCommand}" Key="N" Modifiers="Control"/>
        <KeyBinding Command="{Binding FileService.OpenCommand}" Key="O" Modifiers="Control"/>
        <KeyBinding Command="{Binding FileService.CloseCommand}" Key="F4" Modifiers="Control"/>
        <KeyBinding Command="{Binding FileService.SaveCommand}" Key="S" Modifiers="Control"/>
        <KeyBinding Command="{Binding PrintCommand}" Key="P" Modifiers="Control"/>
        <KeyBinding Command="{Binding AboutCommand}" Key="F1"/>
    </Window.InputBindings>

    <DockPanel>
        <Ribbon DockPanel.Dock="Top" Margin="0,0,0,2">
            <Ribbon.QuickAccessToolBar>
                <RibbonQuickAccessToolBar>
                    <RibbonButton Command="{Binding FileService.SaveCommand}" 
                                  SmallImageSource="{StaticResource SaveImageSource}" 
                                  ToolTipTitle="{x:Static p:Resources.SaveToolTip}" ToolTipDescription="{x:Static p:Resources.SaveToolTipDescription}"/>
                    <RibbonButton Command="ApplicationCommands.Undo" 
                                  SmallImageSource="{StaticResource UndoImageSource}" 
                                  ToolTipTitle="{x:Static p:Resources.UndoToolTip}" ToolTipDescription="{x:Static p:Resources.UndoToolTipDescription}"/>
                    <RibbonButton Command="ApplicationCommands.Redo" 
                                  SmallImageSource="{StaticResource RedoImageSource}" 
                                  ToolTipTitle="{x:Static p:Resources.RedoToolTip}" ToolTipDescription="{x:Static p:Resources.RedoToolTipDescription}"/>
                </RibbonQuickAccessToolBar>
            </Ribbon.QuickAccessToolBar>
            
            <Ribbon.ApplicationMenu>
                <RibbonApplicationMenu KeyTip="F">
                    <RibbonApplicationMenuItem Command="{Binding FileService.NewCommand}" IsEnabled="{Binding IsPrintPreviewVisible, Converter={StaticResource InvertBooleanConverter}}" 
                                               Header="{x:Static p:Resources.NewMenu}" ImageSource="{StaticResource NewLargeImageSource}" 
                                               ToolTipTitle="{x:Static p:Resources.NewToolTip}" ToolTipDescription="{x:Static p:Resources.NewToolTipDescription}"/>
                    <RibbonApplicationMenuItem Command="{Binding FileService.OpenCommand}" IsEnabled="{Binding IsPrintPreviewVisible, Converter={StaticResource InvertBooleanConverter}}" 
                                               Header="{x:Static p:Resources.OpenMenu}" ImageSource="{StaticResource OpenLargeImageSource}" 
                                               ToolTipTitle="{x:Static p:Resources.OpenToolTip}" ToolTipDescription="{x:Static p:Resources.OpenToolTipDescription}"/>
                    <RibbonApplicationMenuItem Command="{Binding FileService.CloseCommand}" IsEnabled="{Binding IsPrintPreviewVisible, Converter={StaticResource InvertBooleanConverter}}" 
                                               Header="{x:Static p:Resources.CloseMenu}" ImageSource="{StaticResource EmptyLargeImageSource}" 
                                               ToolTipTitle="{x:Static p:Resources.CloseToolTip}" ToolTipDescription="{x:Static p:Resources.CloseToolTipDescription}"/>
                    <RibbonApplicationMenuItem Command="{Binding FileService.SaveCommand}" IsEnabled="{Binding IsPrintPreviewVisible, Converter={StaticResource InvertBooleanConverter}}" 
                                               Header="{x:Static p:Resources.SaveMenu}" ImageSource="{StaticResource SaveLargeImageSource}" 
                                               ToolTipTitle="{x:Static p:Resources.SaveToolTip}" ToolTipDescription="{x:Static p:Resources.SaveToolTipDescription}"/>
                    <RibbonApplicationMenuItem Command="{Binding FileService.SaveAsCommand}" IsEnabled="{Binding IsPrintPreviewVisible, Converter={StaticResource InvertBooleanConverter}}" 
                                               Header="{x:Static p:Resources.SaveAsMenu}" ImageSource="{StaticResource EmptyLargeImageSource}" 
                                               ToolTipTitle="{x:Static p:Resources.SaveAsToolTip}" ToolTipDescription="{x:Static p:Resources.SaveAsToolTipDescription}"/>
                    <RibbonSeparator/>
                    <RibbonApplicationMenuItem Command="{Binding PrintCommand}" 
                                               Header="{x:Static p:Resources.PrintMenu}" ImageSource="{StaticResource PrintLargeImageSource}" 
                                               ToolTipTitle="{x:Static p:Resources.PrintToolTip}" ToolTipDescription="{x:Static p:Resources.PrintToolTipDescription}"/>
                    <RibbonApplicationMenuItem Command="{Binding PrintPreviewCommand}" 
                                               Header="{x:Static p:Resources.PrintPreviewMenu}" ImageSource="{StaticResource EmptyLargeImageSource}" 
                                               ToolTipTitle="{x:Static p:Resources.PrintPreviewToolTip}" ToolTipDescription="{x:Static p:Resources.PrintPreviewToolTipDescription}"/>
                    <RibbonSeparator/>
                    <RibbonApplicationMenuItem Command="{Binding ExitCommand}" 
                                               Header="{x:Static p:Resources.ExitMenu}" ImageSource="{StaticResource EmptyLargeImageSource}" 
                                               ToolTipTitle="{x:Static p:Resources.ExitToolTip}" ToolTipDescription="{x:Static p:Resources.ExitToolTipDescription}"/>
                    
                    <RibbonApplicationMenu.AuxiliaryPaneContent>
                        <StackPanel Visibility="{Binding IsPrintPreviewVisible, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=Invert}">
                            <Label Content="{x:Static p:Resources.RecentDocuments}" FontWeight="SemiBold" Margin="0"/>
                            <RibbonSeparator/>
                            <ItemsControl ItemsSource="{Binding FileService.RecentFileList.RecentFiles}" Focusable="False" Margin="0,1,0,0">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <DockPanel Margin="0,0,0,1">
                                            <ToggleButton IsChecked="{Binding IsPinned}" Margin="2,0,0,0" DockPanel.Dock="Right">
                                                <ToggleButton.Style>
                                                    <Style TargetType="ToggleButton" BasedOn="{StaticResource PinRibbonToggleButton}">
                                                        <Setter Property="Content" Value="{StaticResource PinImageSource}"/>
                                                        <Setter Property="ToolTip" Value="{x:Static p:Resources.PinToolTip}"/>
                                                        <Style.Triggers>
                                                            <Trigger Property="IsChecked" Value="True">
                                                                <Setter Property="Content" Value="{StaticResource PinnedImageSource}"/>
                                                                <Setter Property="ToolTip" Value="{x:Static p:Resources.UnpinToolTip}"/>
                                                            </Trigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </ToggleButton.Style>
                                            </ToggleButton>

                                            <RibbonButton Command="{Binding DataContext.FileService.OpenCommand, ElementName=shellWindow}" CommandParameter="{Binding Path}"
                                                          Content="{Binding Path, Converter={StaticResource MenuFileNameConverter}, Mode=OneWay}"
                                                          ToolTip="{Binding Path}"
                                                          Style="{StaticResource RecentDocumentRibbonButton}"/>                                                
                                        </DockPanel>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </StackPanel>
                    </RibbonApplicationMenu.AuxiliaryPaneContent>
                </RibbonApplicationMenu>
            </Ribbon.ApplicationMenu>

            <Ribbon.HelpPaneContent>
                <RibbonButton Command="{Binding AboutCommand}" 
                              SmallImageSource="{StaticResource HelpImageSource}" 
                              ToolTipTitle="{x:Static p:Resources.HelpToolTip}" ToolTipDescription="{x:Static p:Resources.HelpToolTipDescription}"/>
            </Ribbon.HelpPaneContent>

            <RibbonTab Header="{x:Static p:Resources.Home}" KeyTip="H" 
                       Visibility="{Binding IsPrintPreviewVisible, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=Invert, Mode=OneWay}"
                       IsSelected="{Binding IsVisible, RelativeSource={RelativeSource Self}, Mode=OneWay}">
                <RibbonGroup Header="{x:Static p:Resources.Clipboard}">
                    <RibbonButton Command="ApplicationCommands.Paste" 
                                  Label="{x:Static p:Resources.Paste}" KeyTip="V" LargeImageSource="{StaticResource PasteLargeImageSource}" 
                                  ToolTipTitle="{x:Static p:Resources.PasteToolTip}" ToolTipDescription="{x:Static p:Resources.PasteToolTipDescription}"/>
                    <RibbonButton Command="ApplicationCommands.Cut" 
                                  Label="{x:Static p:Resources.Cut}" KeyTip="X" SmallImageSource="{StaticResource CutImageSource}" 
                                  ToolTipTitle="{x:Static p:Resources.CutToolTip}" ToolTipDescription="{x:Static p:Resources.CutToolTipDescription}"/>
                    <RibbonButton Command="ApplicationCommands.Copy" 
                                  Label="{x:Static p:Resources.Copy}" KeyTip="C" SmallImageSource="{StaticResource CopyImageSource}" 
                                  ToolTipTitle="{x:Static p:Resources.CopyToolTip}" ToolTipDescription="{x:Static p:Resources.CopyToolTipDescription}"/>
                </RibbonGroup>

                <RibbonGroup Header="{x:Static p:Resources.Font}">
                    <Grid Margin="0,5,0,5">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="7"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>

                        <RibbonControlGroup HorizontalAlignment="Left">
                            <RibbonToggleButton Command="EditingCommands.ToggleBold" IsChecked="{Binding ShellService.ActiveEditingCommands.IsBold}"
                                                SmallImageSource="{StaticResource BoldImageSource}" KeyTip="B" 
                                                ToolTipTitle="{x:Static p:Resources.BoldToolTip}" ToolTipDescription="{x:Static p:Resources.BoldToolTipDescription}"/>
                            <RibbonToggleButton Command="EditingCommands.ToggleItalic" IsChecked="{Binding ShellService.ActiveEditingCommands.IsItalic}" 
                                                SmallImageSource="{StaticResource ItalicImageSource}" KeyTip="I" 
                                                ToolTipTitle="{x:Static p:Resources.ItalicToolTip}" ToolTipDescription="{x:Static p:Resources.ItalicToolTipDescription}"/>
                            <RibbonToggleButton Command="EditingCommands.ToggleUnderline" IsChecked="{Binding ShellService.ActiveEditingCommands.IsUnderline}" 
                                                SmallImageSource="{StaticResource UnderlineImageSource}" KeyTip="U" 
                                                ToolTipTitle="{x:Static p:Resources.UnderlineToolTip}" ToolTipDescription="{x:Static p:Resources.UnderlineToolTipDescription}"/>
                        </RibbonControlGroup>

                        <StackPanel Orientation="Horizontal" Grid.Row="2">
                            <RibbonControlGroup>
                                <RibbonToggleButton Command="EditingCommands.ToggleNumbering" IsChecked="{Binding ShellService.ActiveEditingCommands.IsNumberedList}" 
                                                    SmallImageSource="{StaticResource NumberingImageSource}" KeyTip="N" 
                                                    ToolTipTitle="{x:Static p:Resources.NumberedList}" ToolTipDescription="{x:Static p:Resources.NumberedListToolTipDescription}"/>
                                <RibbonToggleButton Command="EditingCommands.ToggleBullets" IsChecked="{Binding ShellService.ActiveEditingCommands.IsBulletList}" 
                                                    SmallImageSource="{StaticResource BulletsImageSource}" KeyTip="L" 
                                                    ToolTipTitle="{x:Static p:Resources.BulletedList}" ToolTipDescription="{x:Static p:Resources.BulletedListToolTipDescription}"/>
                            </RibbonControlGroup>
                            
                            <RibbonControlGroup Margin="7,0,3,0">
                                <RibbonButton Command="EditingCommands.DecreaseIndentation" 
                                              SmallImageSource="{StaticResource DecreaseIndentationImageSource}" KeyTip="E" 
                                              ToolTipTitle="{x:Static p:Resources.DecreaseIndentToolTip}" ToolTipDescription="{x:Static p:Resources.DecreaseIndentToolTipDescription}"/>
                                <RibbonButton Command="EditingCommands.IncreaseIndentation" 
                                              SmallImageSource="{StaticResource IncreaseIndentationImageSource}" KeyTip="I" 
                                              ToolTipTitle="{x:Static p:Resources.IncreaseIndentToolTip}" ToolTipDescription="{x:Static p:Resources.IncreaseIndentToolTipDescription}"/>
                            </RibbonControlGroup>
                        </StackPanel>
                    </Grid>
                </RibbonGroup>
                
                <RibbonGroup Header="{x:Static p:Resources.Editing}">
                    <RibbonButton Command="ApplicationCommands.SelectAll" 
                                  Label="{x:Static p:Resources.SelectAll}" SmallImageSource="{StaticResource SelectAllImageSource}" KeyTip="A" 
                                  ToolTipTitle="{x:Static p:Resources.SelectAllToolTip}" ToolTipDescription="{x:Static p:Resources.SelectAllToolTipDescription}"/>
                    <RibbonButton Command="EditingCommands.Delete" 
                                  Label="{x:Static p:Resources.Delete}" SmallImageSource="{StaticResource DeleteImageSource}" KeyTip="D" 
                                  ToolTipTitle="{x:Static p:Resources.DeleteToolTip}" ToolTipDescription="{x:Static p:Resources.DeleteToolTipDescription}"/>
                </RibbonGroup>

                <RibbonGroup Header="{x:Static p:Resources.Proofing}">
                    <RibbonToggleButton IsEnabled="{Binding ShellService.ActiveEditingCommands.IsSpellCheckAvailable}" IsChecked="{Binding ShellService.ActiveEditingCommands.IsSpellCheckEnabled}" 
                                        Label="{x:Static p:Resources.CheckSpelling}" LargeImageSource="{StaticResource CheckSpellingLargeImageSource}" KeyTip="S" 
                                        ToolTipTitle="{x:Static p:Resources.CheckSpelling}" ToolTipDescription="{x:Static p:Resources.CheckSpellingToolTipDescription}"/>
                </RibbonGroup>
            </RibbonTab>

            <RibbonTab Header="{x:Static p:Resources.View}" KeyTip="V" 
                       Visibility="{Binding IsPrintPreviewVisible, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=Invert, Mode=OneWay}">
                <RibbonGroup Header="{x:Static p:Resources.Language}">
                    <RibbonButton Command="{Binding EnglishCommand}" 
                                  Label="{x:Static p:Resources.English}" SmallImageSource="{StaticResource FlagEnImageSource}" KeyTip="E" 
                                  ToolTipTitle="{x:Static p:Resources.English}" ToolTipDescription="{x:Static p:Resources.EnglishToolTipDescription}"/>
                    <RibbonButton Command="{Binding GermanCommand}" 
                                  Label="{x:Static p:Resources.German}" SmallImageSource="{StaticResource FlagDeImageSource}" KeyTip="G" 
                                  ToolTipTitle="{x:Static p:Resources.German}" ToolTipDescription="{x:Static p:Resources.GermanToolTipDescription}"/>
                </RibbonGroup>

                <RibbonGroup Header="{x:Static p:Resources.Zoom}">
                    <RibbonButton Command="{Binding ShellService.ActiveZoomCommands.ZoomInCommand}" 
                                  Label="{x:Static p:Resources.ZoomIn}" LargeImageSource="{StaticResource ZoomInLargeImageSource}" KeyTip="I"
                                  ToolTipTitle="{x:Static p:Resources.ZoomInToolTip}" ToolTipDescription="{x:Static p:Resources.ZoomInToolTipDescription}"/>
                    <RibbonButton Command="{Binding ShellService.ActiveZoomCommands.ZoomOutCommand}" 
                                  Label="{x:Static p:Resources.ZoomOut}" LargeImageSource="{StaticResource ZoomOutLargeImageSource}" KeyTip="O"
                                  ToolTipTitle="{x:Static p:Resources.ZoomOutToolTip}" ToolTipDescription="{x:Static p:Resources.ZoomOutToolTipDescription}"/>
                </RibbonGroup>
            </RibbonTab>
            
            <RibbonTab Header="{x:Static p:Resources.PrintPreview}" KeyTip="P"
                       Visibility="{Binding IsPrintPreviewVisible, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
                <RibbonTab.Style>
                    <Style TargetType="RibbonTab">
                        <!-- It is necessary to set the IsSelected property in a Style.Trigger. Otherwise, it is too fast and overrides the Home tab as selected tab. -->
                        <Setter Property="IsSelected" Value="False"/>
                        <Style.Triggers>
                            <Trigger Property="Visibility" Value="Visible">
                                <Setter Property="IsSelected" Value="True"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </RibbonTab.Style>
                
                <RibbonGroup>
                    <RibbonButton Command="{Binding ClosePrintPreviewCommand}" 
                                  Label="{x:Static p:Resources.ClosePreview}" LargeImageSource="{StaticResource CloseLargeImageSource}" KeyTip="C"
                                  ToolTipTitle="{x:Static p:Resources.ClosePreviewToolTip}" ToolTipDescription="{x:Static p:Resources.ClosePreviewToolTipDescription}"/>
                </RibbonGroup>

                <RibbonGroup Header="{x:Static p:Resources.Print}">
                    <RibbonButton Command="{Binding PrintCommand}" 
                                  Label="{x:Static p:Resources.Print}" LargeImageSource="{StaticResource PrintLargeImageSource}" KeyTip="P"
                                  ToolTipTitle="{x:Static p:Resources.PrintToolTip}" ToolTipDescription="{x:Static p:Resources.PrintToolTipDescription}"/>
                </RibbonGroup>

                <RibbonGroup Header="{x:Static p:Resources.Zoom}">
                    <RibbonButton Command="{Binding ShellService.ActiveZoomCommands.ZoomInCommand}" 
                                  Label="{x:Static p:Resources.ZoomIn}" LargeImageSource="{StaticResource ZoomInLargeImageSource}" KeyTip="I"
                                  ToolTipTitle="{x:Static p:Resources.ZoomInToolTip}" ToolTipDescription="{x:Static p:Resources.ZoomInToolTipDescription}"/>
                    <RibbonButton Command="{Binding ShellService.ActiveZoomCommands.ZoomOutCommand}" 
                                  Label="{x:Static p:Resources.ZoomOut}" LargeImageSource="{StaticResource ZoomOutLargeImageSource}" KeyTip="O"
                                  ToolTipTitle="{x:Static p:Resources.ZoomOutToolTip}" ToolTipDescription="{x:Static p:Resources.ZoomOutToolTipDescription}"/>
                    <RibbonButton Command="{Binding ShellService.ActiveZoomCommands.FitToWidthCommand}" 
                                  Label="{x:Static p:Resources.PageWidth}" SmallImageSource="{StaticResource ZoomPageWidthImageSource}" KeyTip="W"
                                  ToolTipTitle="{x:Static p:Resources.PageWidthToolTip}" ToolTipDescription="{x:Static p:Resources.PageWidthToolTipDescription}"/>
                </RibbonGroup>
            </RibbonTab>
        </Ribbon>
        
        <StatusBar DockPanel.Dock="Bottom">
            <StatusBarItem Content="{x:Static p:Resources.Ready}" Margin="3,0,0,0"/>
            <StatusBarItem HorizontalAlignment="Right">
                <StatusBarItem.Style>
                    <Style TargetType="StatusBarItem" BasedOn="{StaticResource {x:Type StatusBarItem}}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ShellService.ActiveZoomCommands.DefaultZooms}" Value="{x:Null}">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </StatusBarItem.Style>
                
                <StackPanel Orientation="Horizontal">
                    <Label Content="{x:Static p:Resources.ZoomMenu}" Target="{Binding ElementName=zoomBox}" VerticalAlignment="Center" Padding="0" Margin="0"/>
                    <ComboBox x:Name="zoomBox" ItemsSource="{Binding ShellService.ActiveZoomCommands.DefaultZooms}"
                              Text="{Binding ShellService.ActiveZoomCommands.Zoom, UpdateSourceTrigger=LostFocus, Converter={StaticResource PercentConverter}}" 
                              IsEditable="True" DropDownClosed="ZoomBoxDropDownClosedHandler" KeyDown="ZoomBoxKeyDownHandler" Margin="7,0,0,0" Width="65"
                              Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}">
                    </ComboBox>
                </StackPanel>
            </StatusBarItem>
        </StatusBar>
        
        <ContentPresenter Content="{Binding ContentView}"/>
    </DockPanel>
</RibbonWindow>
